﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Business;

namespace ReportForSCC
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            task = Authenticated.Instance;
            try
            {
                // prod
                signature = task.Login("p8api", "THQthq@1987", "DEF");

                //test
                //signature = task.Login("p8quanth", "QTHqth@1987", "DEF");
            }
            catch
            {

            }
            
        }

        private List<Flight> listFlights;
        private Authenticated task;
        private string signature=string.Empty;


        private void Form1_Load(object sender, EventArgs e)
        {
            cmbFrom.SelectedIndex = 0;
            cmbTo.SelectedIndex = 1;
           
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            this.FlightBindingSource.DataSource = null;
            this.reportViewer1.RefreshReport();
            try
            {
                listFlights = Business.GetFlightInfomation.GetFlightStatus(cmbFrom.SelectedItem.ToString(), cmbTo.SelectedItem.ToString(), dateTimePicker1.Value, dateTimePicker2.Value, signature);
                this.FlightBindingSource.DataSource = listFlights;
                this.reportViewer1.RefreshReport();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show( ex.Message,"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            task.Logout(signature);
        }
    }
}